
import { parseTime } from '@/utils/common'
export function isvalidUsername(str) {
  const valid_map = ['admin', 'editor']
  return valid_map.indexOf(str.trim()) >= 0
}

export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}
export function isPhone(data) {
  return /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(data)
}
export function isMobile(data) {
  return /^1[3456789]\d{9}$/.test(data)
}
export function isPhoneOrMobile(data) {
  return /^1[3456789]\d{9}$/.test(data) || /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(data)
}
export function isEmail(data) {
  return /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/ig.test(data)
}
export function isFox(data) {
  return /^(\d{3,4}-)?\d{7,8}$/ig.test(data)
}
export function isAfterNow(data) {
  const beginDate = new Date(data).getTime()
  const now = new Date(parseTime(new Date(), '{y}-{m}-{d}')).getTime()
  if (beginDate < now) {
    return false
  } else {
    return true
  }
}
export function isCn(data) {
  return /^[\u4E00-\u9FFF]+$/ig.test(data)
}
export function isNotSpe(data) { // 只能是数字字母_
  return /^[0-9a-zA-Z_]+$/ig.test(data)
}
export function isIdCard(data) {
  return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(data)
}
export function isPostcode(data) {
  return /^[1-9][0-9]{5}$/.test(data)
}
